package testtiles.state;

import testtiles.object.Unit;
import butines.core.math2d.Vector2D;

public class UnitChaseToEnemyState extends AbstractState<Unit> {
	
	private static final UnitChaseToEnemyState instance = new UnitChaseToEnemyState();
	
	public static UnitChaseToEnemyState getInstance() {
		return instance;
	}

	@Override
	public void enter(Unit unit) {
		Vector2D target = unit.getEnemy().getPosition();
		
		unit.getSteering().getSeek().on();
		unit.getSteering().getSeek().setTarget(target);
		
		unit.getAnimations().getWalk();
		
	}

	@Override
	public void leave(Unit owner) {
		owner.getSteering().getSeek().off();
	}

	@Override
	public void execute(Unit unit) {
		Unit enemy = unit.getEnemy();
		
		if (enemy == null || enemy.isAlive() == false) {
			unit.doStay();
			return;
		}
		
		Vector2D target = enemy.getPosition();
		unit.getSteering().getSeek().setTarget(target);
		
//		float minDist = enemy.getRadius() + unit.getRadius() + (unit.getWeapon().getRange() * .7f);
//		float curDist = enemy.distance(unit);
//		
//		boolean canAttackEnemy = curDist <= minDist ;
//		
//		if (canAttackEnemy) {
//			unit.changeState(UnitAttackState.getInstance());
//			return;
//		}
		
		
				
	}
		
}
